﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class SelectedServerInfo : MonoBehaviour
    {
        public ServerPanel serverPanel;
        public GameObject serverInfoLabel;
        public GameObject serverMaintainLabel;

        //ProtoBuf.Message.ConfigServerZone info = null;
        public void Refresh(ProtoBuf.Message.ConfigServerZone serverInfo)
        {
            if (serverInfo != null)
            {
                //this.info = serverInfo;
                if (!string.IsNullOrEmpty(serverInfo.display))
                {
                    serverInfoLabel.GetComponent<UILabel>().text = serverInfo.display + "-" + serverInfo.name;
                }
                else
                {
                    serverInfoLabel.GetComponent<UILabel>().text = serverInfo.serverId + "-" + serverInfo.name;
                }
                if (serverInfo.state == Login.ServerState.maintain)
                {
                    serverMaintainLabel.SetActive(true);
                }
                else
                {
                    serverMaintainLabel.SetActive(false);
                }
            }
            else
            {
                Reset();
            }
        }

        public void Reset()
        {
            serverInfoLabel.GetComponent<UILabel>().text = "";
            //info = null;
        }

        public void OnSelectServerInfoClick()
        {
            serverPanel.ShowServerList();
        }

        public void Show()
        {
            gameObject.SetActive(true);
        }

        public void Hide()
        {
            gameObject.SetActive(false);
        }

    }
}